package service

import (

	"app/api/sys/model"
	"log"
	"strings"
	"git.oschina.net/zhgk/goutil"
	"git.oschina.net/zhgk/sqldb"
)

func DoLogin(userName, passWord string) (res bool, msg string, data string) {
	if userName == "" {
		return false, "用户名不能为空", ""
	}

	if passWord == "" {
		return false, "用户密码不能为空", ""
	}
	//二次加密
	passWord = goutil.EncodeSha1(strings.ToUpper(passWord))
	log.Println(passWord)
	sqldb.UserDefaultDB()
	userInfo, err := sqldb.QueryRowMap(model.QueryUserInfoSQL, userName)
	if err != nil {
		log.Println("查询登录用户信息出错：", err.Error())
		return false, err.Error(), ""
	}
	if userInfo == nil || len(userInfo) == 0 {
		return false, "用户名或密码不正确，请重新输入！", ""
	}

	userPass := userInfo.GetString(strings.ToUpper("user_pass"), "")
	if userPass != passWord {
		return false, "用户名或密码不正确，请重新输入！", ""
	}
	return true, "用户登录成功！", userName
}
